<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
</head>
<body layadmin-themealias="default">

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body" pad15="">
                    <div class="layui-form" wid100="" lay-filter="">
                        <input type="hidden" name="id" value="{$taskinfo.id}">

                        <div class="layui-form-item">
                            <label class="layui-form-label">任务类别</label>
                            <div class="layui-input-inline">
                                <input type="text" value="{$type_cate_name}" disabled class="layui-input"/>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">任务标题</label>
                            <div class="layui-input-inline">
                                <input type="text" value="{$taskinfo.name}" disabled class="layui-input"/>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">条件次数</label>
                            <div class="layui-input-inline">
                                <input placeholder="请输入条件次数" class="layui-input" name="frequency" disabled value="{$taskinfo.frequency|default=1}" data-val="{$taskinfo.frequency|default=1}" lay-verify="required|number" onkeyup="clearNoNum(this)">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">规则说明</label>
                            <div class="layui-input-block">
                                <textarea placeholder="" class="layui-textarea" name="description" lay-verify="required">{$taskinfo.description}</textarea>
                            </div>
                        </div>
                        <div class="layui-form-item" style="margin-bottom: 0px">
                            <label class="layui-form-label">权重</label>
                            <div class="layui-input-block">
                                <input placeholder="请输入权重" class="layui-input" name="weight" lay-verify="required|number" value="{$taskinfo.weight|default=1}" onkeyup="clearNoNum(this)">
                            </div>
                        </div>

                        <div class="layui-row">
                            <div  style="color: red;height:20px;line-height: 20px;margin-left:130px;font-size: 12px;margin-bottom: 2px">前端排序 相同完成度 按权重的大小倒序排序</div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">奖励经验值</label>
                            <div class="layui-input-block">
                                <input placeholder="请输入需要奖励多少经验值" class="layui-input" name="exp" lay-verify="number" value="{$taskinfo.exp}" onkeyup="clearNoNum(this)">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">奖励钻石</label>
                            <div class="layui-input-block">
                                <input placeholder="请输入需要奖励多少钻石" class="layui-input" name="gold" lay-verify="number" value="{$taskinfo.gold}" onkeyup="input_num(this)">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">奖励宝石</label>
                            <div class="layui-input-block">
                                <input placeholder="请输入需要奖励多少宝石" class="layui-input" name="diamond" value="{$taskinfo.diamond}" lay-verify="number" onkeyup="input_num(this)">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">奖励贵族</label>
                            <div class="layui-input-block">
                                <input placeholder="奖励贵族的意思是：1为1天，以此类推；" class="layui-input" name="nobel_day" value="{$taskinfo.nobel_day}" lay-verify="number" onkeyup="clearNoNum(this)">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">奖励礼物</label>
                            <div class="layui-input-inline" id="giftArea" style="width:auto">
                                <!--<div class="layui-form-item">-->
                                <!--    <div class="layui-inline">-->
                                <!--        <button id="addGift" type="button" class="layui-btn layui-btn-warm layui-btn-sm">-->
                                <!--            <i class="layui-icon">&#xe654;</i>添加礼物-->
                                <!--        </button>-->
                                <!--    </div>-->
                                <!--</div>-->
                                <div class="layui-input-inline">
                                    <select name="gift_id" class="layui-select" lay-verify="">
                                        <option value="">请先选择礼物</option>
                                        {volist name="gift_list" id="vo"}
                                        <option value="{$vo.id}" {$gift_reward && $gift_reward.id==$vo.id?'selected':''}>{$vo.title}</option>
                                        {/volist}
                                    </select>
                                </div>

                                <div class="layui-inline">
                                    <label class="layui-form-label">数量：</label>
                                    <div class="layui-input-inline">
                                        <input placeholder="礼物数量" class="layui-input" name="gift_num" value="{$gift_reward.num??0}" lay-verify="" onkeyup="clearNoNum(this)">
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">奖励道具</label>
                            <div class="layui-input-inline" id="propsArea" style="width:auto">
                                <!--<div class="layui-form-item">-->
                                <!--    <div class="layui-inline">-->
                                <!--        <button id="addProps" type="button" class="layui-btn layui-btn-warm layui-btn-sm">-->
                                <!--            <i class="layui-icon">&#xe654;</i>添加道具-->
                                <!--        </button>-->
                                <!--    </div>-->
                                <!--</div>-->
                                <div class="layui-input-inline">
                                    <select name="props_id" class="layui-select" lay-verify="">
                                        <option value="">请先选择道具</option>
                                        {volist name="props_new" id="vo"}
                                        <option value="{$vo.id}" {$props_reward && $props_reward.id==$vo.id?'selected':''}>{$vo.name}</option>
                                        {/volist}
                                    </select>
                                </div>

                                <div class="layui-inline">
                                    <label class="layui-form-label">数量：</label>
                                    <div class="layui-input-inline">
                                        <input placeholder="数量" class="layui-input" name="props_num" value="{$props_reward.num??0}" lay-verify="" onkeyup="clearNoNum(this)">
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">转盘抽奖次数</label>
                            <div class="layui-input-block">
                                <input placeholder="转盘抽奖次数" class="layui-input" name="luck_draw" value="{$taskinfo.luck_draw}" lay-verify="number" onkeyup="clearNoNum(this)">
                            </div>
                        </div>

                        <!---
                        <div class="layui-form-item">
                            <label class="layui-form-label">任务开始时间</label>
                            <div class="layui-input-block">
                                <input placeholder="请选择限时任务开始时间" type="text" class="layui-input" name="begin_time" value="{$taskinfo.begin_time}" id="begin_time_input" readonly>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">任务结束时间</label>
                            <div class="layui-input-block">
                                <input placeholder="请选择限时任务结束时间" type="text" class="layui-input" name="end_time" value="{$taskinfo.end_time}" id="end_time_input" readonly>
                            </div>
                        </div> -->

                        <div class="layui-form-item">
                            <label class="layui-form-label">跳转页面标识</label>
                            <div class="layui-input-inline">
                                <select name="page_tag" class="layui-select">
                                    <option value="">请选择</option>
                                    {volist name="page_tag_cate" id="vo"}
                                    <option value="{$key}" {$taskinfo.page_tag==$key?'selected':''}>{$vo}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">状态</label>
                            <div class="layui-input-block">
                                <input type="radio" name="status" value="0" title="启用" {$taskinfo.status==0?'checked':''}/>
                                <input type="radio" name="status" value="1" title="停用" {$taskinfo.status==1?'checked':''}/>
                            </div>
                        </div>


                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit="" lay-filter="task-edit">确认保存</button>
                                <button class="layui-btn layui-btn-primary layuiadmin-btn-push" data-type="cancel">取消</button>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>

<script src="/layuiadmin/layui/layui.js"></script>
<script src="/static/jquery.min.js"></script>
<script src="/assets/cos-js-sdk-v5/cos-js-sdk-v5.js"></script>
<script>
    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
        , version: "{:config('other.ui_version')}"
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'task', 'form', 'admin', 'laydate'], function () {
        var $ = layui.$
            , laydate = layui.laydate
            , form = layui.form;

        //执行一个laydate实例
        $(this).removeAttr("lay-key");
        laydate.render({
            elem: '#begin_time_input',
            type: 'datetime',
            trigger: 'click',
            min: '<?php echo date("Y-m-d H:i:s");?>',
        });
        laydate.render({
            elem: '#end_time_input',
            type: 'datetime',
            trigger: 'click',
            min: '<?php echo date("Y-m-d H:i:s");?>',
        });

        //事件
        var active = {
            cancel: function () {
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index); //再执行关闭
            }
        };

        $('.layui-btn.layuiadmin-btn-push').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });


        //动态添加礼物选择
        var gift_total = '{:count($gift_reward)}';
        $("#addGift").click(function () {
            var str = `<div class="layui-form-item">
                                    <div class="layui-input-inline">
                                        <select name="gift[${gift_total}][id]" class="layui-select" lay-verify="required">
                                            <option value="">请先选择礼物</option>
                                            {volist name="gift_list" id="vo"}
                                            <option value="{$vo.id}">{$vo.title}</option>
                                            {/volist}
                                        </select>
                                    </div>

                                    <div class="layui-inline">
                                        <label class="layui-form-label">礼物数量：</label>
                                        <div class="layui-input-inline">
                                            <input placeholder="礼物数量" class="layui-input" name="gift[${gift_total}][num]" value="1" lay-verify="number">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <button type="button" class="layui-btn layui-btn-danger  layui-btn-sm removeGift">
                                            <i class="layui-icon">&#xe67e;</i>
                                        </button>
                                    </div>
                                </div>`


            $("#giftArea").append(str);
            layui.form.render("select");//重新渲染 固定写法
            gift_total++;
        });

        //删除动态添加的礼物选择
        $("body").on('click', ".removeGift", function () {
            //元素移除前校验是否被引用
            var approvalName = $(this).parent().prev('div.layui-input-inline').children().val();
            var parentEle = $(this).parent().parent();
            parentEle.remove();
        });
    });

    function clearNoNum(obj) {
        obj.value = obj.value.replace(/[^\d]/g, "");
        obj.value = obj.value.replace(/^\./g, "");
    }

    function input_num(obj){
        obj.value = obj.value.replace(/[^\d.]/g,"");
        obj.value = obj.value.replace(/^\./g,"");
        obj.value = obj.value.replace(/\.{2,}/g,".");
        obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
        obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');

        if(obj.value.indexOf(".")> 0  && obj.value.indexOf("0")>2){
            obj.value= parseFloat(obj.value);
        }
        if(obj.value.indexOf(".")> 0  && obj.value.lastIndexOf("0")>2){
            obj.value= parseFloat(obj.value);
        }
        if (obj.value.indexOf(".") <= 0 && obj.value != "") {
            obj.value = parseFloat(obj.value);
        }
    }
</script>
</body>
</html>
